#include "StdAfx.h"
#include "CameraEditor.h"
#include "AnyView.h"

REGISTERE_EDITOR(CCameraEditorPan)

CCameraEditorPan::CCameraEditorPan(void):
m_nX(0), m_nY(0)
{
}

CCameraEditorPan::~CCameraEditorPan(void)
{
}
CString CCameraEditorPan::GetID()
{
	return _T("134F4171-36CE-45d5-9B5D-FCE9E5141BA8");
}
EditorState CCameraEditorPan::OnLButtonDown(UINT nFlags, long x, long y)
{
	m_nX = x;
	m_nY = y;

	return ES_CONTINUE;
}

void CCameraEditorPan::OnMouseMove(UINT nFlags, long x, long y)
{
	if(nFlags & MK_LBUTTON)
	{
		GetView()->Pan(x-m_nX, m_nY-y);
	}

	m_nX = x;
	m_nY = y;
}

//////////////////////////////////////////////////////////////////////////
REGISTERE_EDITOR(CCameraEditorRotate)

CCameraEditorRotate::CCameraEditorRotate(void)
{
}

CCameraEditorRotate::~CCameraEditorRotate(void)
{
}
CString CCameraEditorRotate::GetID()
{
	return _T("2C8A1BE4-B7A2-4690-BA01-9DC8CD42E350");
}
EditorState CCameraEditorRotate::OnLButtonDown(UINT nFlags, long x, long y)
{
	GetView()->StartRotation(x, y);  

	return ES_CONTINUE;
}
void CCameraEditorRotate::OnMouseMove(UINT nFlags, long x, long y)
{
	if(nFlags & MK_LBUTTON)
	{
		GetView()->Rotation(x, y);
	}

}

//////////////////////////////////////////////////////////////////////////
REGISTERE_EDITOR(CCameraEditorZoom)

CCameraEditorZoom::CCameraEditorZoom(void):
m_nX(0), m_nY(0)
{
}

CCameraEditorZoom::~CCameraEditorZoom(void)
{
}
CString CCameraEditorZoom::GetID()
{
	return _T("43DC16CE-802F-4eb1-9383-3D30338D6BA3");
}

EditorState CCameraEditorZoom::OnLButtonDown(UINT nFlags, long x, long y)
{
	m_nX = x;
	m_nY = y;

	return ES_CONTINUE;
}
void CCameraEditorZoom::OnMouseMove(UINT nFlags, long x, long y)
{

	if(nFlags & MK_LBUTTON)
	{
		long delataY = m_nY-y;
		GetView()->Zoom(m_nX, m_nY, x-delataY, y-delataY);
	}

	m_nX = x;
	m_nY = y;
}

//////////////////////////////////////////////////////////////////////////
#define REGISTER_STANDARD_CAMERA(EGUID, Type) \
	static CRegEditorHelper s_regEditorHelper##Type( EGUID,\
	new ATools::TObjectCreator<CCameraEditorStandard<Type>,CEditorCreator>()); 

enum StandardProjection
{
	SC_FRONT_VIEW		=	V3d_Xpos,
	SC_BACK_VIEW		=	V3d_Xpos,
	SC_LEFT_VIEW		=	V3d_Ypos,
	SC_RIGHT_VIEW		=	V3d_Yneg,
	SC_TOP_VIEW			=	V3d_Zpos,
	SC_BOTTOM_VIEW		=	V3d_Zneg,
	SC_ISOMETRIC_VIEW	=	V3d_XposYnegZpos
};

//////////////////////////////////////////////////////////////////////////
// Standard View
template<StandardProjection CameraType>
class CCameraEditorStandard :
	public CShareEditorBase
{	
public:
	CCameraEditorStandard(void){}
	~CCameraEditorStandard(void){}
	virtual EditorState Start()
	{
		GetView()->SetProj(CameraType);
		return ES_FINISHED;
	}
};

REGISTER_STANDARD_CAMERA(_T("217E0B97-79B7-41dc-A4BF-4A4D10DB193E"), SC_FRONT_VIEW);
REGISTER_STANDARD_CAMERA(_T("6E2BCADF-29DF-4f95-B9F8-134A30BCC542"), SC_BACK_VIEW);
REGISTER_STANDARD_CAMERA(_T("B4D2024F-243F-4321-A27B-11909019D7F6"), SC_LEFT_VIEW);
REGISTER_STANDARD_CAMERA(_T("334841AB-5BEA-4ef1-8C08-29DCEA2900E8"), SC_RIGHT_VIEW);
REGISTER_STANDARD_CAMERA(_T("29049329-5D8C-489b-A872-1EED5953D7F4"), SC_TOP_VIEW);
REGISTER_STANDARD_CAMERA(_T("C7872E77-79B3-42b7-B295-D847C7074317"), SC_BOTTOM_VIEW);
REGISTER_STANDARD_CAMERA(_T("1F53D55A-5E7B-4ad5-857B-EC1CBE442955"), SC_ISOMETRIC_VIEW);